package com.niuke;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * 1. 跳房子Ⅱ
 * 题目描述参考下面链接，注意只可以挑选三个步骤
 * https://blog.csdn.net/guorui_java/article/details/131140694
 */
public class NiukeMoni4 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int count = scanner.nextInt();

        List<Integer> steps = new ArrayList<>();
        String stepStr = scanner.next();
        String[] stepTmp = stepStr.split(",");
        for (String step : stepTmp) {
            steps.add(Integer.parseInt(step));
        }

        int stepSize = steps.size();
        int resultCount = stepSize * (stepSize - 1) * (stepSize - 2) / 6;
        System.out.println("resultCount = " + resultCount);

        int[] result = new int[3];

        // 用了暴力循环，最垃圾的解法，肯定还有更优解。
        jump:
        for (int i = 0; i < (stepSize - 2); i++) {
            if (steps.get(i) > count) {
                continue;
            }

            for (int j = i + 1; j < (stepSize - 1); j++) {
                if (steps.get(i) + steps.get(j) > count) {
                    continue;
                }

                for (int k = j + 1; k < stepSize; k++) {
                    if (steps.get(i) + steps.get(j) + steps.get(k) == count) {
                        result[0] = steps.get(i);
                        result[1] = steps.get(j);
                        result[2] = steps.get(k);
                        break jump;
                    }
                }
            }
        }

        System.out.println("result = " + Arrays.toString(result));
    }

}
